package done.normal_101_200;

import com.study.common.TreeNode;
import org.junit.Test;

import static com.study.util.LogUtil.info;

/**
 * 114. Flatten Binary Tree to Linked List 二叉树展开为链表
 * <p>
 * 给定一个二叉树，原地将它展开为链表。
 * 例如，给定二叉树
 * <p>
 * 1
 * / \
 * 2   5
 * / \   \
 * 3   4   6
 * <p>
 * 将其展开为：
 * 1
 * \
 * 2
 * \
 * 3
 * \
 * 4
 * \
 * 5
 * \
 * 6
 * <p>
 * 2019-05-10 21:28
 **/
@SuppressWarnings("all")
public class FlattenBinaryTreeToLinkedList {

    public void flatten(TreeNode root) {
        // 190510 first
    }

    @Test
    public void test() {
        TreeNode root = new TreeNode(1,
                new TreeNode(2,
                        4, 5), new TreeNode(3,
                null, 8));
        flatten(root);
        info(root);
    }
}










































/*
public void flatten(TreeNode root) {
    if (root == null)
        return;

    flatten(root.left);
    flatten(root.right);

    TreeNode tmp = root.right;
    root.right = root.left;
    root.left = null;

    while (root.right != null)
        root = root.right;

    root.right = tmp;
}
*/
